<?php
/**
 * breedable_register_post_types()
 *
 * The meat of this whole operation, this is where we register our post types
 *
 * @global array $breedable_page_titles
 */
function breedable_register_post_types() {
	global $breedable_page_titles;

	// Products
    $labels = array(
		'name'               => _x( 'Breedables'                  , 'post type name'             , 'breedable' ),
		'singular_name'      => _x( 'Breedable'                   , 'post type singular name'    , 'breedable' ),
		'add_new'            => _x( 'Add New'                   , 'admin menu: add new breedable', 'breedable' ),
		'add_new_item'       => __( 'Add New Breedable'           , 'breedable' ),
		'edit_item'          => __( 'Edit Breedable'              , 'breedable' ),
		'new_item'           => __( 'New Breedable'               , 'breedable' ),
		'view_item'          => __( 'View Breedable'              , 'breedable' ),
		'search_items'       => __( 'Search Breedables'           , 'breedable' ),
		'not_found'          => __( 'No breedables found'         , 'breedable' ),
		'not_found_in_trash' => __( 'No breedables found in Trash', 'breedable' ),
		'menu_name'          => __( 'Breedables'                  , 'breedable' ),
		'parent_item_colon'  => '',
      );
    $args = array(
		'capability_type'      => 'post',
		'supports'             => array( 'title', 'editor' ),
		'hierarchical'         => true,
		'exclude_from_search'  => false,
		'public'               => true,
		'show_ui'              => true,
		'show_in_nav_menus'    => true,
		'menu_icon'            => BREEDABLE_CORE_IMAGES_URL . "/breedable-icon.png",
		'labels'               => $labels,
		'query_var'            => true,
		'register_meta_box_cb' => 'breedable_meta_boxes',
		'rewrite'              => array(
			'slug'       => str_replace( basename( home_url() ), '', $breedable_page_titles['products'] ) . '/%breedable_product_category%',
			'with_front' => false
		)
	);
	$args = apply_filters( 'breedable_register_post_types_products_args', $args );
	register_post_type( 'breedable', $args );

	do_action( 'breedable_register_post_types_after' );
}
add_action( 'init', 'breedable_register_post_types', 8 );

/**
 * Post Updated Messages
 */
function breedable_post_updated_messages( $messages ) {
	global $post, $post_ID;

	$messages['breedable'] = array(
		0  => '', // Unused. Messages start at index 1.
		1  => sprintf( __( 'Product updated. <a href="%s">View product</a>', 'breedable' ), esc_url( get_permalink( $post_ID ) ) ),
		2  => __( 'Custom field updated.', 'breedable' ),
		3  => __( 'Custom field deleted.', 'breedable' ),
		4  => __( 'Product updated.', 'breedable' ),
		// translators: %s: date and time of the revision
		5  => isset( $_GET['revision'] ) ? sprintf( __('Product restored to revision from %s', 'breedable' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
		6  => sprintf( __( 'Product published. <a href="%s">View product</a>', 'breedable' ), esc_url( get_permalink( $post_ID ) ) ),
		7  => __( 'Product saved.', 'breedable' ),
		8  => sprintf( __( 'Product submitted. <a target="_blank" href="%s">Preview product</a>', 'breedable' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
		9  => sprintf( __( 'Product scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview product</a>', 'breedable' ),
			// translators: Publish box date format, see http://php.net/date
			date_i18n( __( 'M j, Y @ G:i', 'breedable' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ),
		10 => sprintf( __( 'Product draft updated. <a target="_blank" href="%s">Preview product</a>', 'breedable' ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ),
	);

	return $messages;
}
add_filter( 'post_updated_messages', 'breedable_post_updated_messages' );
?>